//index.js
//获取应用实例
const app = getApp()
var targetAppId = null; //存储跳转的appId
var pathUrl = null;     //存储跳转的路径
var cb = null;          //存储回调路径
var taskId = "bc4a57fc312340d19f370df52dd9ddda"; //默认值
var token=
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4MzZlNmI4ZWRlMjM0NDNhOGVmOWM3M2E3ZmM2MmZkZiIsImV4cCI6MTU3MTQ3MzQwMH0.gR7uCCgS_jBY-zuUe1S3AbCwHXS8st1bp7bAXXVprrA"; //默认值
Page({
  data: {
    info:{},
    getLaunch:{
      taskId: null,
      token: null
    },
    infotwo:'',
    iffotwoshow:''
  },
  //事件处理函数
  toUser(){
    this.setData({
      iffotwoshow:this.data.infotwo
    })
    wx.navigateToMiniProgram({
      //appId: 'wx465cafe21521e82f',//送审完毕请写成变量，即info.xxx,xxx为获取数据对应的属性名
      appId: targetAppId,
      //pages/index/index
      path: pathUrl + "?" + cb,// 这个数据为跳转小程序的链接，
      extraData: {
        url: cb
      },
      // envVersion: 'develop',
      success(res) {
        // 打开成功
      }
    })
   
  },
  onLoad: function (options) {
    var obj = wx.getLaunchOptionsSync()
    console.log('来源数据:', obj.query)
	var data = JSON.stringify(obj)
      this.setData({
	      infotwo:data, 
        getLaunch: obj.query != undefined ? obj.query : { taskId: taskId, token: token }
      })
    console.log('来源数据:', this.data.getLaunch)
    console.log('task:', this.data.getLaunch.taskId)
    console.log('token:', this.data.getLaunch.token)
  var that = this
  wx.request({
    url: 'https://www.zizhibangshou.com/app/api/v1/kol/user/getKolUserTaskDetails',
    data: {
      //"taskId": "bc4a57fc312340d19f370df52dd9ddda",//obj.referrerInfo.taskId
      "taskId": this.data.getLaunch.taskId
    },
    header: {
      'content-type': 'application/json', // 默认值
      //token后面冒号后面跟obj.referrerInfo.token
      // "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJmMWQ5NmI1ODg0ZmM0ZDZmYThlYmVjODdkOWE1YTJmNSIsImV4cCI6MTU3MDkzNjIyNX0.kOyFiH8U4l0MaJ8SC7iUTrvyB4GPmV-vbwBZGGbn7PI",
      "token": this.data.getLaunch.token
    },
    method: 'POST',
    success(res) {
      that.setData({
        info: res.data.body
      })
      console.log(res.data.body)
      if (null != res.data.body){
        targetAppId = res.data.body.appId
        pathUrl = res.data.body.path
        cb = res.data.body.taskUrl
        console.log("targetAppId  " + targetAppId)
      }
    }
  })

  },
 
})
